home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / DEL_LINE.ASM < prev    next >
Assembly Source File  |  1996-03-22  |  3KB  |  132 lines

  1. ; DEL_LINE.ASM for E32 - Copyright (C) 1994 - 1996 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ; 03/22/1996 DH: changed lb to public symbol
  5.  
  6. include    model.inc
  7.  
  8. public    del_l, udel_l, del_eol, close_space, line_length
  9.  
  10. ; use MEMCOPY in place of REP  MOVSB
  11. ; because MEMCOPY is faster when it counts on huge files
  12. extrn    memcopy:near
  13. extrn    endd:near
  14. extrn    find_start:near
  15. extrn    find_next:near
  16. extrn    locate:near
  17. extrn    insert_string:near
  18. extrn    sub_push:near
  19. extrn    home:near
  20.  
  21. include    dataseg.inc
  22. public    lb
  23. extrn    dirty_bits:byte, cur_posn:word
  24. extrn    cursor:dword, filesiz:dword
  25. extrn    left_margin:word
  26. line_flag    db 0
  27. line_length    dd 0
  28. lb    db 256 dup (?)
  29. @curseg    ends
  30.  
  31. include    codeseg.inc
  32. ;
  33. ; this deletes a line, placing it in the line buffer
  34. ;
  35. del_l    proc    near
  36.     mov    line_flag,-1
  37.     call    find_start    ; find start of this line
  38.     mov    cursor,esi    ; this will be the new cursor position
  39.     push    esi        ; save the cursor position
  40.     call    find_next    ; find the next line
  41.     mov    ecx,esi        ; CX will hold the line length
  42.     pop    esi        ; get back the new cursor position
  43. del_end:sub    ecx,esi        ; number of bytes on line
  44.     cmp    ecx,100h    ; is line too long to fit?
  45.     jb    short not_too_long
  46.     mov    ecx,100h    ; only save 256 characters
  47. not_too_long:
  48.     mov    line_length,ecx    ; store length of deleted line
  49.     jecxz    no_del_l
  50.     lea    edi,lb
  51.     push    ecx
  52.     push    ds
  53.     pop    es
  54.  
  55.     push    ds
  56.     push    fs
  57.     pop    ds
  58.     call    memcopy        ; put deleted line in buffer
  59.     pop    ds
  60.  
  61.     pop    eax        ; get back line length
  62.     call    close_space
  63.  
  64.     mov    dx,cur_posn    ; get cursor row/col
  65.     mov    esi,cursor    ; get new cursor location
  66.     call    locate        ; adjust screen position
  67.     clc
  68.     ret
  69. del_l    endp
  70.  
  71. ;
  72. ; CLOSE_SPACE closes a hole in the file
  73. ; call with EAX = bytes to remove
  74. ;
  75. close_space:
  76.     mov    ecx,filesiz    ; get the file size
  77.     sub    filesiz,eax    ; new file size
  78.     call    sub_push    ; adjust saved offset if nessesary
  79.     mov    esi,cursor    ; get new cursor location
  80.     mov    edi,esi
  81.     add    esi,eax        ; ESI points to end of file
  82.     sub    ecx,esi        ; length of remaining file
  83.     or    dirty_bits,11000001b
  84.     jecxz    no_del_l
  85.  
  86.     push    ds
  87.     mov    ax,fs
  88.     mov    es,ax
  89.     mov    ds,ax
  90.     call    memcopy        ; remove end of line from active buffer
  91.     pop    ds
  92. no_del_l:
  93.     clc
  94.     ret
  95.  
  96. ;
  97. ; delete from the cursor position to the end of the line
  98. ;
  99. del_eol    proc    near
  100.     mov    line_flag,0
  101.     push    cursor        ; find start of this line
  102.     push    left_margin
  103.     call    endd        ; move to the end of the line
  104.     pop    left_margin
  105.     pop    esi        ; get back the starting cursor
  106.     mov    ecx,cursor    ; offset of the end of the line
  107.     mov    cursor,esi    ; restore starting cursor
  108.     jmp    del_end
  109. del_eol    endp
  110.  
  111. ;
  112. ; This undeletes a line by copying it from the line buffer into the file
  113. ;
  114. udel_l    proc    near
  115.     push    es
  116.     cmp    line_flag,0        ; is this an end-of-line only?
  117.     je    short udel_eol        ; if yes, don't home the cursor
  118.     call    home            ; move the cursor to home
  119. udel_eol:
  120.     push    fs
  121.     pop    es
  122.     mov    eax,line_length        ; length of deleted line
  123.     lea    esi,lb
  124.     call    insert_string
  125.     clc
  126.     pop    es
  127.     ret
  128. udel_l    endp
  129.  
  130. @curseg    ends
  131.     end
  132.